<?php 
/**
 * 年检记录model类
 * @Author    紫梦
 * @DateTime  2018-01-17
 * @copyright 响响租车
 * @version   1.0
 */
namespace app\common\model;
use think\Model;

class Inspect extends Model
{
	protected $type = [
	        'inspect_time' => 'timestamp:Y-m-d',           
	    ];
	protected $insert = ['agency_id'];
    
    protected function setAgencyIdAttr()
    {
        return session('admin.agency_id');
    }    

	// 定义全局的查询范围
    protected static function base($query)
    {
    	$agency = session('admin.agency_id');
        if($agency==1){
            // $query->where('delete_time',null);

        }else{
            $query->where(['agency_id'=>$agency]);

        }
    		    	
    }

    public function InspectFile()
    {
        return $this->hasMany('InspectFile','inspect_id');
    }    

    public function scopeInspectNum($query,$time)
    {
        $query->where('inspect_time','<',$time);
    }
}